package tech.aistar.util;

import org.apache.commons.dbcp.BasicDataSource;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 本类用来演示: 连接池
 *
 * @author: success
 * @date: 2022/8/12 4:16 下午
 */
public class PoolUtil {
    public static BasicDataSource basicDataSource = new BasicDataSource();

    static{
        basicDataSource.setUrl(ConfigUtil.getValue("url"));
        basicDataSource.setUsername(ConfigUtil.getValue("username"));
        basicDataSource.setPassword(ConfigUtil.getValue("password"));
        basicDataSource.setInitialSize(Integer.valueOf(ConfigUtil.getValue("initialSize")));
        basicDataSource.setMaxActive(Integer.valueOf(ConfigUtil.getValue("maxActive")));
        basicDataSource.setMaxIdle(Integer.valueOf(ConfigUtil.getValue("maxIdle")));
        basicDataSource.setMinIdle(Integer.valueOf(ConfigUtil.getValue("minIdle")));
        basicDataSource.setMaxWait(Long.valueOf(ConfigUtil.getValue("maxWait")));
    }

    public static Connection getConnection() throws SQLException {
        return basicDataSource.getConnection();
    }
}
